package indi.zhifa.study2025.oa.admin.controller;

import indi.zhifa.engine.core.common.web.ann.ZhiFaRestController;
import indi.zhifa.study2025.oa.admin.facade.menu.IMenuFacade;
import indi.zhifa.study2025.oa.common.util.ConstantUtil;
import indi.zhifa.study2025.oa.model.expose.menu.dto.MenuCreateDto;
import indi.zhifa.study2025.oa.model.expose.menu.dto.MenuEditDto;
import indi.zhifa.study2025.oa.model.expose.menu.vo.MenuTreeNode;
import indi.zhifa.study2025.oa.model.expose.menu.vo.MenuVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Validated
@RequiredArgsConstructor
@Tag(name = "菜单接口")
@ZhiFaRestController
@RequestMapping(ConstantUtil.API_PREFIX + "/menuMgr")
public class MenuController {

    final IMenuFacade mMenuFacade;

    @Operation(summary = "创建菜单")
    @PostMapping("/{id}/add")
    public MenuVo addMenu(@PathVariable("id") Long pParentId, @RequestBody MenuCreateDto pMenuCreateDto){
        MenuVo rtn = mMenuFacade.addMenu(pParentId, pMenuCreateDto);
        return rtn;
    }

    @Operation(summary = "编辑菜单")
    @PostMapping("/{id}/edit")
    public MenuVo edit(@PathVariable("id") Long pId, @RequestBody  MenuEditDto pMenuEditDto){
        MenuVo rtn = mMenuFacade.edit(pId, pMenuEditDto);
        return rtn;
    }

    @Operation(summary = "删除菜单")
    @DeleteMapping("/{id}")
    public MenuVo delete(@PathVariable("id") Long pId){
        MenuVo rtn = mMenuFacade.delete(pId);
        return rtn;
    }

    @Operation(summary = "infoAll:获取菜单树")
    @GetMapping("/{id}/all")
    public MenuTreeNode getTreeNode(@PathVariable("id") Long pId){
        MenuTreeNode rtn = mMenuFacade.getTreeNode(pId);
        return rtn;
    }

    @Operation(summary = "info")
    @GetMapping("/{id}")
    public MenuVo info(@PathVariable("id") Long pId){
        MenuVo rtn = mMenuFacade.info(pId);
        return rtn;
    }


}
